//
//  priceViewCell.m
//  YouGoWeGo
//
//  Created by 范业君 on 14-11-25.
//  Copyright (c) 2014年 LiuFei. All rights reserved.
//

#import "priceViewCell.h"
#import "priceModel.h"
#import "UIImageView+WebCache.h"

@implementation priceViewCell

- (void)dealloc
{
    [_name1 release];
    [_name2 release];
    [_pModel release];
    [_showImage release];
    [_titleLabel release];
    [_startAddress release];
    [_price release];
    [_money release];
    [self removeObserver:self forKeyPath:@"pModel"];
    [super dealloc];
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.showImage = [[UIImageView alloc] initWithFrame:CGRectZero];
        //[_showImage setBackgroundColor:[UIColor redColor]];
        [_showImage.layer setCornerRadius:10];
        [self.contentView addSubview:_showImage];
        [_showImage release];
        
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        //[_titleLabel setBackgroundColor:[UIColor redColor]];
        [_titleLabel setFont:[UIFont systemFontOfSize:14]];
        [_titleLabel setNumberOfLines:0];
        [self.contentView addSubview:_titleLabel];
        [_titleLabel release];
        
        self.startAddress = [[UILabel alloc] initWithFrame:CGRectZero];
        //[_startAddress setBackgroundColor: [UIColor redColor]];
        [_startAddress setFont:[UIFont systemFontOfSize:12]];
        [self.contentView addSubview:_startAddress];
        [_startAddress release];
        
        
        self.name1 = [[UILabel alloc] initWithFrame:CGRectZero];
       // [_name1 setBackgroundColor:[UIColor redColor]];
        [_name1 setText:@"市场价:"];
        [_name1 setFont:[UIFont systemFontOfSize:12]];
        [self.contentView addSubview:_name1];
        [_name1 release];
        
        
        self.name2 = [[UILabel alloc] initWithFrame:CGRectZero];
        //[_name2 setBackgroundColor:[UIColor redColor]];
        [_name2 setFont:[UIFont systemFontOfSize:12]];
        [_name2 setText:@"元起"];
        [self.contentView addSubview:_name2];
        [_name2 release];

        
        
        self.price = [[UILabel alloc] initWithFrame:CGRectZero];
        //[_price setBackgroundColor:[UIColor redColor]];
        [_price setFont:[UIFont systemFontOfSize:12]];
        [self.contentView addSubview:_price];
        [_price release];
        
        
        self.money = [[UILabel alloc] initWithFrame:CGRectZero];
        //[_money setBackgroundColor: [UIColor redColor]];
        [self.contentView addSubview:_money];
        [_money release];
        
        
        [self addObserver:self forKeyPath:@"pModel" options:NSKeyValueObservingOptionNew context:nil];
    }
    
    return self;
}



- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if ([keyPath isEqualToString:@"pModel"]) {
        [self.titleLabel setText:self.pModel.title];
        [self.showImage setImageWithURL:[NSURL URLWithString:self.pModel.cover]];
        NSNumber *number1 = [NSNumber numberWithInteger:self.pModel.market_price];
        [self.price setText:[NSString stringWithFormat:@"%@", number1]];
        NSNumber *number2 = [NSNumber numberWithInteger:self.pModel.min_price];
        [self.money setText:[NSString stringWithFormat:@"%@", number2]];
        [self.startAddress setText:self.pModel.depart_place];
    }
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    [_showImage setFrame:CGRectMake(10, 10, 100, 100)];

    [_titleLabel setFrame:CGRectMake(_showImage.frame.size.width + 20, 10,170, 38)];
    
    [_startAddress setFrame:CGRectMake(_titleLabel.frame.origin.x, _titleLabel.frame.origin.y + _titleLabel.frame.size.height, 50, 20)];
    
    [_name1 setFrame:CGRectMake(_titleLabel.frame.origin.x, _startAddress.frame.origin.y + _startAddress.frame.size.height, 50, 25)];
    
    [_price setFrame:CGRectMake(_name1.frame.origin.x + _name1.frame.size.width, _name1.frame.origin.y, 40, 20)];
    
    [_money setFrame:CGRectMake(_titleLabel.frame.origin.x, _price.frame.origin.y + _price.frame.size.height + 5, 50, 20)];

    
    [_name2 setFrame:CGRectMake(_money.frame.origin.x + _money.frame.size.width, _money.frame.origin.y, 50, 20)];
    
    
}













- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
